#ifndef SERIALPORTSERVICE_H
#define SERIALPORTSERVICE_H

#include <QObject>
#include <QDebug>
#include <QThread>
#include <QSerialPort>
#include <QSerialPortInfo>
#include <QTimer>

class SerialPortService : public QObject
{
    Q_OBJECT
public:
    explicit SerialPortService(QObject *parent = nullptr);
    ~SerialPortService();

    bool IsOpen(void);
    void SetSerialInfo(QString serial_name,QSerialPort::BaudRate serial_baud);

public slots:
    void slots_OpenSerialPort(void);
    void slots_CloseSerialPort(void);
    void slots_SerialWriteData(const QByteArray& data); //通过串口写数据

private slots:
    void slots_serialReadData(const QByteArray& data);

signals:
    //发送数据到其它线程
    void sig_SerialReceiveData(QByteArray data);

private:
    bool is_open=false;
    QSerialPort *serial_port=NULL;
    QString serial_name;

    QSerialPort::BaudRate serial_baud;


    QTimer *serial_rec_timer=NULL;
    QByteArray serial_rec_data;

};

#endif // SERIALPORTSERVICE_H
